package com.huanying.goodjob.paymentactivity;

import java.util.HashMap;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.log4j.Logger;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.huanying.framework.BaseController;
import com.huanying.framework.PageBean;
import com.huanying.framework.user.User;
import com.huanying.framework.user.UserController;
import com.huanying.framework.user.UserService;
import com.huanying.goodjob.community.Area;
import com.huanying.goodjob.community.Community;
import com.huanying.goodjob.community.CommunityService;
import com.huanying.goodjob.jobtype.JobtypeService;
import com.huanying.goodjob.skill.Skill;
import com.huanying.goodjob.skill.SkillService;

import com.huanying.goodjob.job.Job;
import com.huanying.goodjob.job.Jobitem;

@Controller
public class PaymentactivityController extends BaseController{
	@Autowired
	private PaymentactivityService paymentactivityService;

	private static Logger logger = Logger.getLogger(PaymentactivityController.class);

	// 充值
	@RequestMapping(value = "/recharge.do", method = RequestMethod.GET)
	@ResponseBody
	public String recharge(String user_id,String money,String banktype,String jsoncallback) {
		Map<String, String> map = new HashMap<String, String>();
		try {
			paymentactivityService.rechargeRecord(Integer.parseInt(user_id), Double.parseDouble(money), Integer.parseInt(banktype));
			map.put("flag", "1");
			logger.info("充值成功");
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			map.put("flag", "0");
			logger.error("充值失败", e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			map.put("flag", "0");
			logger.error("充值失败", e);
		}
		Gson gson = new Gson();
		String str = gson.toJson(map);
		return jsoncallback + "(" + str + ")";
	}
	// 提现
	@RequestMapping(value = "/withdraw_cash.do", method = RequestMethod.GET)
	@ResponseBody
	public String withdraw_cash(String user_id,String money,String banktype,String jsoncallback) {
		Map<String, String> map = new HashMap<String, String>();
		try {
			paymentactivityService.withdraw_cashRecord(Integer.parseInt(user_id), Double.parseDouble(money), Integer.parseInt(banktype));
			map.put("flag", "1");
			logger.info("提现成功");
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			map.put("flag", "0");
			logger.error("提现失败", e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			map.put("flag", "0");
			logger.error("提现失败", e);
		}
		Gson gson = new Gson();
		String str = gson.toJson(map);
		return jsoncallback + "(" + str + ")";
	}
	// 转账
	@RequestMapping(value = "/moneyRecord.do", method = RequestMethod.GET)
	@ResponseBody
	public String moneyChange(String user_id,String userobject_id,String amount,String direction,String bankType,String jsoncallback) {
		Map<String, String> map = new HashMap<String, String>();
		try {
			paymentactivityService.moneyRecord(Integer.parseInt(user_id),Integer.parseInt(userobject_id), Double.parseDouble(amount),Integer.parseInt(direction),Integer.parseInt(bankType));
			map.put("flag", "1");
			logger.info("转账成功");
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			map.put("flag", "0");
			logger.error("转账失败", e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			map.put("flag", "0");
			logger.error("转账失败", e);
		}
		Gson gson = new Gson();
		String str = gson.toJson(map);
		return jsoncallback + "(" + str + ")";
	}
}
